public class Demo28 {
    static class Result {
        public int sum = 0;
        public Object lock = new Object();
    }

    public static void main(String[] args) {
        Result result = new Result();
        Thread t1 = new Thread(() -> {
            synchronized (result.lock) {
                for (int i = 0; i < 10000; i++) {
                    result.sum++;
                }

                result.lock.notify();
            }
        });

        t1.start();

        synchronized (result.lock) {
            try {
                while (result.sum == 0) {
                    result.lock.wait();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(result.sum);
        }
    }
}
